<?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script language="javascript">
		function charu(url,img_class,width_img) {
			var form_post = parent.document.getElementById("content_new_article")
			form_post.value += "<p style=\"width:100%;\"><a href=\""+url+"\"><img class=\"sided "+img_class+"\" width=\""+width_img+"\" src=\""+url+"\"/></a></p>";
		}
	</script>
	<!-- <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" /> -->
</head><body><div id="content_upload"><?php
	// start 包含文件
	include_once('../mysql_connection.php');
	include_once('../setting.php');
	include_once('../lib/functions.php');
	// end 包含文件

	// start 处理上传附件
	if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
		$ext_name= extend($_FILES['fujian_file']['name']);	// 取得文件的扩展名
		if ( $_FILES['fujian_file']['error'] > 0 or $_FILES['fujian_file']['size'] > $setting['fujian_file_size'] ) {
			echo '上传错误，或者文件太大';
		} else if ($ext_name!='gif' and $ext_name!='png' and $ext_name!='jpg') {
			echo '文件格式必须为 gif， png 或者 jgp。';
		} else {
			// start 保存附件到upload文件夹
			$time_file = time();
			$file_name_url = '../upload/'.$time_file.'_'.$_FILES['fujian_file']['name'];
			$charu_url = 'upload/'.$time_file.'_'.$_FILES['fujian_file']['name'];
			move_uploaded_file($_FILES['fujian_file']['tmp_name'],$file_name_url);
			// end 保存附件到upload文件夹
			// start 把文件url存入数据库
			$file_all_url = '../upload/'.$time_file.'_'.$_FILES['fujian_file']['name'];
			$query_insert_file = "insert into `files` (`url`,`name`) values ('".$file_all_url."','".$_FILES['fujian_file']['name']."')";
			$mysql_connection->query($query_insert_file);
			// end 把附件url存入数据库
			$query_file_id = "select `id` from `files` where `url`='".$file_all_url."'";
			$result_file_id = $mysql_connection->query($query_file_id);
			$result_file_id = $result_file_id->fetch_assoc();
			$result_file_id = $result_file_id['id'];
		?>
		<a href="javascript:charu('<?php echo $charu_url;?>','align<?php echo $setting['image_align'];?>','<?php echo $setting['image_width'];?>')">插入帖子</a>
		<?php
		}
	}
	// end 处理上传附件
?>
<div id="content_b_upload">
	<!-- start 上传文件表单 -->
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post">
		<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
		上传文件(限2M)：<input name="fujian_file" id="fujian_file" type="file" />
		<input type="submit" value="上传" />
		<input type="hidden" name="type_hidden" id="type_hidden" value="file" />
	</form>
	<!-- end 上传文件表单 -->
</div></body></html>
